package com.clp.protocol.iec104.iec104.client.pipeline.handler;

import com.clp.protocol.iec104.iec104.apdu.Apdu;
import com.clp.protocol.iec104.iec104.client.Master;
import com.clp.protocol.iec104.iec104.client.pipeline.DuplexMasterHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ITypeMasterHandler extends DuplexMasterHandler {
    public ITypeMasterHandler(Master master) {
        super(master);
    }

    @Override
    public void whenActive(ChannelHandlerContext ctx) throws Exception {

    }

    @Override
    public void whenRecvingApdu(ChannelHandlerContext ctx, Apdu apdu) {
        if (apdu.isIType()) {
            log.debug("收到I帧： \n{}", apdu);
        }

        passRecvingApdu(ctx, apdu);
    }

    @Override
    public void whenSendingApdu(ChannelHandlerContext ctx, Apdu apdu, ChannelPromise promise) {
        if (apdu.isIType()) {
            log.debug("发送I帧： \n{}", apdu);
        }

        passSendingApdu(ctx, apdu, promise);
    }

    @Override
    public void whenInActive(ChannelHandlerContext ctx) throws Exception {

    }

    @Override
    public void whenExceptionCaught(ChannelHandlerContext ctx, Throwable cause) {

    }
}
